package net.funtip.jdbc;

import java.util.logging.Level;
import java.util.logging.Logger;

import com.p6spy.engine.spy.appender.P6Logger;

public class P6SpyLoggerImpl implements P6Logger {

	protected Logger log = Logger.getLogger(this.getClass().getName());

	private JDBCLogger jdbcLogger = JDBCLogger.getInstance();

	@Override
	public void logSQL(int connectionId, String now, long elapsed, String category, String prepared, String sql) {
		if ("statement".equalsIgnoreCase(category)) {
			if (log.isLoggable(Level.FINEST)) {
				log.finest("connectionId = " + connectionId + "elapsed = " + elapsed + ", now = " + now + 
						", category = " + category + ", prepared = " + prepared + ", sql = " + sql);
			}
			jdbcLogger.logSqlQuery(prepared, elapsed);
		} else {
			if (log.isLoggable(Level.FINEST)) {
				log.finest("connectionId = " + connectionId + "elapsed = " + elapsed + ", now = " + now + 
						", category = " + category + ", prepared = " + prepared + ", sql = " + sql);
			}
		}
	}

	@Override
	public void logException(Exception e) {
		log.severe(e.getMessage());
	}

	@Override
	public void logText(String text) {
		log.info(text);
	}

}
